package com.yzp.sort;

import java.util.Arrays;

/**
 * Description
 * 冒泡排序
 *
 * @className: BubbleSort
 * @author: yanzhouping
 * @date: 2019/8/15 9:37
 */
public class BubbleSort {

    public static void main(String[] args) {
        int[] arr = new int[]{1, 2, 1, 5, 3, 5, 64, 6, 9};
        arr = bubbleSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    /**
     * 冒泡排序
     *
     * @param array
     * @return
     */
    public static int[] bubbleSort(int[] array) {
        if (array.length == 0) {
            return array;
        }
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array.length - 1 - i; j++) {
                if (array[j + 1] < array[j]) {
                    int temp = array[j + 1];
                    array[j + 1] = array[j];
                    array[j] = temp;
                }
            }
        }
        return array;
    }
}
